package com.api.core.domain.model;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.api.common.utils.StringUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;

import java.util.HashSet;
import java.util.List;
import java.util.Set;


@Getter
@Setter
public class ElementTreeModel{
    private Long elementId;
    private JSONObject elementNameLocales;
    @JsonIgnore
    private String strElementName;
    private Set<String> datColSet;

    public void setStrElementName(String strElementName) {
        if(StringUtils.isNoneBlank(strElementName)){
            this.elementNameLocales = JSONObject.parseObject(strElementName);
        }
        this.strElementName = strElementName;
    }
    public void setDatColSet(String strDatColSet) {
        if (StringUtils.isNotBlank(strDatColSet)) {
            List<String> ja = JSONArray.parseArray(strDatColSet).toList(String.class);
            this.datColSet = new HashSet<>(ja);
        } else {
            this.datColSet = null;
        }
    }
}